package tiandang.core.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tiandang.core.dao.RewardLogMapper;
import tiandang.core.model.RewardLog;
import tiandang.core.service.RewardLogService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RewardLogServiceImpl implements RewardLogService {

  @Autowired
  private RewardLogMapper rewardLogMapper;

  @Override
  public void save(RewardLog rewardLog) {
    rewardLogMapper.insertSelective(rewardLog);
  }

  @Override
  public Object getList(Integer managerId, Integer currentPage, Integer limit) {
    Map<String, Object> map = new HashMap<>();
    int offset = (currentPage - 1) * limit;
    List<RewardLog> rewardLogList = rewardLogMapper.getListByParams(managerId, limit, offset);
    int totalCount = rewardLogMapper.countByParams();
    map.put("rewardLogList", rewardLogList);
    map.put("totalCount", totalCount);

    return map;
  }
}
